﻿using System;
using System.Collections.Specialized;
using System.Configuration;
using System.Web.Management;
using Microsoft.ServiceHosting.ServiceRuntime;

namespace WASM.WebSite.Logic.Logging
{
	public class AzureEventProvider : WebEventProvider
	{
		public string _eventLogName;

		public override void Initialize(string name, NameValueCollection config)
		{
			base.Initialize(name, config);

			_eventLogName = config.Get("eventLogName");

			if (String.IsNullOrEmpty(_eventLogName))
				throw new ConfigurationErrorsException("EventLogName is Required for AzureEventProvider.");
		}

		public override void ProcessEvent(WebBaseEvent webEvent)
		{
			string logMessage = webEvent.ToString();
			RoleManager.WriteToLog(_eventLogName, logMessage);
		}

		public override void Shutdown() { }

		public override void Flush() { }
	}
}
